#!/usr/bin/python
# -*- coding: utf-8 -*-

import unittest
from trivmoo.design_patterns.factory.test_classes import MyClass2, MyClass1

class ClassicalFactory(object):    
    def create(self, s_type, d_parameters):
        if (s_type == "MyClass1"):
            return MyClass1(d_parameters)
        
        if (s_type == "MyClass2"):
            return MyClass2(d_parameters)
        
        return None # or raise exception
        

class TestClassicalFactory(unittest.TestCase):
    def test_factory(self):
        classicalFactory = ClassicalFactory()
        a_object = classicalFactory.create("MyClass1", {})
        self.assertTrue(isinstance(a_object, MyClass1))
        a_object = classicalFactory.create("MyClass2", {})
        self.assertTrue(isinstance(a_object, MyClass2))
        a_object = classicalFactory.create("MyClass3", {})
        self.assertEqual(a_object, None)
        
if __name__ == "__main__":
    unittest.main()